package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.constant.UserConstant;
import com.tbit.uqbike.client.dao.core.UserMsgDao;
import com.tbit.uqbike.client.pojo.UserMsg;
import com.tbit.uqbike.client.service.UserMsgService;
import com.tbit.uqbike.client.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: chen
 * @Description: 用户消息
 * @Date: 创建于 10:54 2020/10/28
 */
@Service
public class UserMsgServiceImpl implements UserMsgService {
    @Autowired
    private UserMsgDao userMsgDao;

    @Override
    public List<UserMsg> queryPage(Integer userId, Integer msgState, Integer msgType,
                                   Integer currentPage, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("msgState", msgState);
        map.put("msgType", msgType);
        /**新分页方式*/
        map.put("pageNO", currentPage);
        map.put("rowCount", pageSize);
        return userMsgDao.queryPage(map);
    }

    @Override
    public Integer queryCount(Integer userId, Integer msgState, Integer msgType) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("msgState", msgState);
        map.put("msgType", msgType);
        return userMsgDao.queryCount(map);
    }

    @Override
    public void edit(UserMsg userMsg) {
        userMsg.setReadTime(DateTimeUtil.getNowTime());
        userMsg.setMsgState(UserConstant.READED);
        userMsgDao.edit(userMsg);
    }
}
